package com.glsc.ngateway.flowable.config;

import com.glsc.ngateway.flowable.listener.global.ProcessCompleteListener;
import com.glsc.ngateway.flowable.listener.global.ProcessStartListener;
import com.glsc.ngateway.flowable.listener.global.TaskCompleteListener;
import com.glsc.ngateway.flowable.listener.global.TaskCreateListener;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.engine.RuntimeService;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FlowableListenerInit {

    private static Logger logger = LoggerFactory.getLogger(FlowableListenerInit.class);

    @Autowired
    private SpringProcessEngineConfiguration configuration;
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private ProcessCompleteListener processCompleteListener;
    @Autowired
    private TaskCreateListener taskCreateListener;
    @Autowired
    private TaskCompleteListener taskCompleteListener;
    @Autowired
    private ProcessStartListener processStartListener;


    @Bean
    public void addEventListener() {

        logger.info("addEventListener初始化");
        //任务完成全局监听
        //dispatcher.addEventListener(activityCompleteListener, FlowableEngineEventType.TASK_CREATED);

        runtimeService.addEventListener(processStartListener, FlowableEngineEventType.PROCESS_CREATED);
        runtimeService.addEventListener(taskCreateListener, FlowableEngineEventType.TASK_CREATED);
        runtimeService.addEventListener(processCompleteListener, FlowableEngineEventType.PROCESS_COMPLETED);
        runtimeService.addEventListener(taskCompleteListener, FlowableEngineEventType.TASK_COMPLETED);
    }


}
